﻿//  --  P3109M0050 將圖片限制改為 440 * 440 by Joe -- 2009/03/15

/*
	子畫面的大小
*/
var global_TableName = "";
window.onload = PageLoad;
var program_id = "VNDW0032.aspx";
var _DialogWidth = "600px";
var _DialogHeight = "450px";
var dialogStr = "dialogWidth=" + _DialogWidth + ";dialogHeight=" + _DialogHeight + ";center=yes;border=thin;help=no;status=no;resizable=no;";
var program_id1 = "CLASS_DESC.aspx";
var _DialogWidth1 = "520px";
var _DialogHeight1 = "200px";
var dialogStr1 = "dialogWidth=" + _DialogWidth1 + ";dialogHeight=" + _DialogHeight1 + ";center=yes;border=thin;help=no;status=no;resizable=no;toolbar=no;location=no;title=no";
var program_id2 = "DELIVERY_TERM_DESC.aspx";
var _DialogWidth2 = "350px";
var _DialogHeight2 = "150px";
var dialogStr2 = "dialogWidth=" + _DialogWidth2 + ";dialogHeight=" + _DialogHeight2 + ";center=yes;border=thin;help=no;status=no;resizable=no;toolbar=no;location=no;title=no";

// joe add 淑宜修改案

function AD_PRICE_OnClick() {

    //alert((0.5099 + 0.049).toFixed(4)); 
    //alert((1 - 0.9999).toFixed(4)); 
    //alert((0.5589 * 10000).toFixed(4)); 

    var result = $("#txtADVISED_PRICE").val() * 1.05;
    if (result != undefined) {
        var num7 = new Number(result);
        // num7 = num7.toFixed(3) 
        num7 = Math.round(num7)
        $("#txtADVISED_PRICE_T").val(num7);
    }
}


function PageLoad() {
    try {
        /*if (document.all.drpDELIVERY_TERM.value=="FOB_Seaport")
		{
			document.all.lblSEAPORT.style.display=""; 
			document.all.txtSEAPORT.style.display=""; 
		}
		else
		{	
			document.all.lblSEAPORT.style.display="none"; 
			document.all.txtSEAPORT.style.display="none"; 
		}
		*/
        if ($("#rdoMATERIAL_TYPE_0").prop("checked")) {
            $("#SFLAG").css("display", "")
        }
        else {
            $("#SFLAG").css("display", "none")
        }
    }
    catch (e) {
        alert(e.Message);
    }
    finally {

    }

}
function DialogBtnSave_OnClick() {
    try {
        //英文簡稱
        $("#hidCLASS").val($("#drpVENDOR_KIND").val());
        if ($("#txtENGLISH_SHORTNAME").val() == "") {
            $("#lblENGLISH_SHORTNAME_ERR").text(GetMessageByID("MSG019").text);
        }
        else {
            $("#lblENGLISH_SHORTNAME_ERR").text("");
        }
        //前置時間
        if ($("#txtLEAD_TIME").val() == "") {
            $("#lblLEAD_TIME_ERR").text(GetMessageByID("MSG019").text);
        }
        else {
            $("#lblLEAD_TIME_ERR").text("");
            if (isNaN($("#txtLEAD_TIME").val())) {
                $("#lblLEAD_TIME_ERR").text(GetMessageByID("MSG024").text);
            }
        }

        // 效期檢核
        /*
        if(document.all.txtQUOTATION_VALID_DATE.value !="")
            {
                if(!isDate(document.all.txtQUOTATION_VALID_DATE.value))
                {
                    document.all.lblQUOTATION_VALID_DATE_ERR.innerText=GetMessageByID("MSG021").text;
                }
                else
                {
                    var ServerDate=getServerInfoByClient("date");
                    if(document.all.txtQUOTATION_VALID_DATE.value < ServerDate)
                    {
                        document.all.lblQUOTATION_VALID_DATE_ERR.innerText=GetMessageByID("MSG062").text;
                    }
                }
            }
            else
            {
                document.all.lblQUOTATION_VALID_DATE_ERR.innerText=GetMessageByID("MSG019").text;
            }
        */

        //貨至倉有效期
        if ($("#txtEXP_DATELINE").val() != "") {
            $("#lblEXP_DATELINE_ERR").text("");
            if (isNaN($("#txtEXP_DATELINE").val())) {
                $("#lblEXP_DATELINE_ERR").text(GetMessageByID("MSG024").text);
            }
        }
        //單位兌換比'
        if ($("#txtCOEFFICIENT").val() == "") {
            $("#lblCOEFFICIENT_ERR").text(GetMessageByID("MSG019").text);
        }
        else {
            $("#lblCOEFFICIENT_ERR").text("");
            if (isNaN($("#txtCOEFFICIENT").val())) {
                $("#lblCOEFFICIENT_ERR").text(GetMessageByID("MSG024").text);
            }
            else {
                $("#lblCOEFFICIENT_ERR").text("");
            }
        }
        //供應單價

        if ($("#txtSUPPLY_PRICE").val() == "") {
            $("#lblSUPPLY_PRICE_ERR").text(GetMessageByID("MSG019").text);
        }
        else {
            $("#lblSUPPLY_PRICE_ERR").text("");
            if (isNaN($("#txtSUPPLY_PRICE").val())) {
                $("#lblSUPPLY_PRICE_ERR").text(GetMessageByID("MSG024").text);
            }
            else {
                $("#lblSUPPLY_PRICE_ERR").text("");
                if ($("#txtSUPPLY_PRICE").val() == 0) {
                    $("#lblSUPPLY_PRICE_ERR").text(GetMessageByID("MSG038").text);
                }
                else {
                    chknum($("#txtSUPPLY_PRICE")[0], $("#lblSUPPLY_PRICE_ERR")[0]);
                }
            }
        }
        //物品體積-長
        if ($("#txtDIMENSION_L").val() == "") {
        }
        else {
            $("#lblDIMENSION_L_ERR").text("");
            if (isNaN($("#txtDIMENSION_L").val())) {
                $("#lblDIMENSION_L_ERR").text(GetMessageByID("MSG024").text);
            }
            else {
                $("#lblDIMENSION_L_ERR").text("");
                if ($("#txtDIMENSION_L").val() == 0) {
                    $("#lblDIMENSION_L_ERR").text(GetMessageByID("MSG038").text);
                }
                else {
                    chknum($("#txtDIMENSION_L")[0], $("#lblDIMENSION_L_ERR")[0]);
                }
            }
        }
        //物品體積-寬
        if ($("#txtDIMENSION_W").val() == "") {
        }
        else {
            $("#lblDIMENSION_W_ERR").text("");
            if (isNaN($("#txtDIMENSION_W").val())) {
                $("#lblDIMENSION_W_ERR").text(GetMessageByID("MSG024").text);
            }
            else {
                $("#lblDIMENSION_W_ERR").text("");
                if ($("#txtDIMENSION_W").val() == 0) {
                    $("#lblDIMENSION_W_ERR").text(GetMessageByID("MSG038").text);
                }
                else {
                    chknum($("#txtDIMENSION_W")[0], $("#lblDIMENSION_W_ERR")[0]);
                }
            }
        }
        //物品體積-高
        if ($("#txtDIMENSION_H").val() == "") {
        }
        else {
            $("#lblDIMENSION_H_ERR").text("");
            if (isNaN($("#txtDIMENSION_H").val())) {
                $("#lblDIMENSION_H_ERR").text(GetMessageByID("MSG024").text);
            }
            else {
                $("#lblDIMENSION_H_ERR").text("");
                if ($("#txtDIMENSION_H").val() == 0) {
                    $("#lblDIMENSION_H_ERR").text(GetMessageByID("MSG038").text);
                }
                else {
                    chknum($("#txtDIMENSION_H")[0], $("#lblDIMENSION_H_ERR")[0]);
                }
            }
        }
        //物品毛重
        if ($("#txtGROSS_WEIGHT").val() == "") {

        }
        else {
            $("#lblGROSS_WEIGHT_ERR").text("");
            if (isNaN($("#txtGROSS_WEIGHT").val())) {
                $("#lblGROSS_WEIGHT_ERR").text(GetMessageByID("MSG024").text);
            }
            else {
                $("#lblGROSS_WEIGHT_ERR").text("");
                if ($("#txtGROSS_WEIGHT").val() == 0) {
                    $("#lblGROSS_WEIGHT_ERR").text(GetMessageByID("MSG038").text);
                }
                else {
                    chknum1($("#txtGROSS_WEIGHT")[0], $("#lblGROSS_WEIGHT_ERR")[0]);
                }
            }
        }
        //建議售價        
        if (isNaN($("#txtADVISED_PRICE").val())) {
            $("#lblADVISED_PRICE_ERR").text(GetMessageByID("MSG024").text);
        }
        else {
            $("#lblADVISED_PRICE_ERR").text("");
            chknum($("#txtADVISED_PRICE")[0], $("#lblADVISED_PRICE_ERR")[0]);
        }        
        //免稅商店售價
        if (isNaN($("#txtDUTY_FREE_PRICE").val())) {
            $("#lblDUTY_FREE_PRICE_ERR").text(GetMessageByID("MSG024").text);
        }
        else {
            $("#lblDUTY_FREE_PRICE_ERR").text("");
            chknum($("#txtDUTY_FREE_PRICE")[0], $("#lblDUTY_FREE_PRICE_ERR")[0]);
        }
        //建議售價
        if (isNaN($("#txtAVERAGE_PRICE").val())) {
            $("#lblAVERAGE_PRICE_ERR").text(GetMessageByID("MSG024").text);
        }
        else {
            chknum($("#txtAVERAGE_PRICE")[0], $("#lblAVERAGE_PRICE_ERR")[0]);
        }
        //存檔檢核
        if ($("#lblENGLISH_SHORTNAME_ERR").text() == "" && $("#lblAVERAGE_PRICE_ERR").text() == "" && $("#lblDUTY_FREE_PRICE_ERR").text() == "" && $("#lblADVISED_PRICE_ERR").text() == "" && $("#lblLEAD_TIME_ERR").text() == "" && $("#lblEXP_DATELINE_ERR").text() == "" && $("#lblCOEFFICIENT_ERR").text() == "" && $("#lblSUPPLY_PRICE_ERR").text() == "" && $("#lblDIMENSION_L_ERR").text() == "" && $("#lblDIMENSION_W_ERR").text() == "" && $("#lblDIMENSION_H_ERR").text() == "" && $("#lblGROSS_WEIGHT_ERR").text() == "" && $("#lblPATH1_ERR").text() == "" && $("#lblPATH2_ERR").text() == "" && $("#lblPATH3_ERR").text() == "" && $("#lblQUOTATION_VALID_DATE_ERR").text() == "") {
            return true;
        }
        else {
            alert(GetMessageByID("MSG020").text);
            return false;
        }
    }
    catch (e) {
        alert(e.Message);
        return false;
    }
    finally {

    }
}



function btnVIEW_OnClick(path) {
    try {
        var code = $("#txtCODE_SEQ").val();
        var serial_no;
        if (path == 1) {
            serial_no = $("#txtPIC_NO1").val();
        }
        if (path == 2) {
            serial_no = $("#txtPIC_NO2").val();
        }
        if (path == 3) {
            serial_no = $("#txtPIC_NO3").val();
        }
        var action_type = "?serial_no=" + serial_no + "&code=" + code;
        //var result = window.showModalDialog(program_id + action_type, dialogStr, dialogStr ,true);
        var result = window.open(program_id + action_type, '', dialogStr, true);

    }
    catch (e) {
        alert(GetMessageByID("MSG040").text);
    }
    finally {

    }
    return false;
}


function check_name(o, o1, o2) {
    try {
        if (o.value != "") {
            o2.disabled = false;
            var len = (o.value.length) - 3;
            if (o.value.substr(len, 3) == "jpg" || o.value.substr(len, 3) == "JPG") {
                o1.innerText = "";
                var img = new Image();
                img.onload = function () {
                }
                img.src = o.value;
                var size = getServerInfoByClient("config", "FileSize");
                if ($("#drpVENDOR_KIND").val() == "G") {

                    var iWidth;
                    var iHeight;
                    iWidth = img.width;
                    iHeight = img.height;

                    if ((800 < img.width) || (800 < img.height)) {
                        //判段長寬是否為800*800以上
                        o1.innerText = GetMessageByID("MSG070").text;
                        alert("目前規格:" + img.width + "*" + img.height + ", 不符合800*800以上的尺吋");

                    }

                    else {
                        o1.innerText = "";
                        var iSize1;
                        if (img.width > img.height)
                            iSize1 = img.width - img.height;
                        else
                            iSize1 = img.height - img.width;


                        if (50 < iSize1) {
                            o1.innerText = GetMessageByID("MSG071").text;
                            alert("目前規格:" + img.width + "*" + img.height + ", 長寬差距不得超過50piex");
                            //判段長寬差距不得超過50 piex
                        }
                        else {
                            if (600 <= img.fileSize) {
                                //檔案不得超過600k
                                o1.innerText = GetMessageByID("MSG072").text;
                                alert("目前規格:" + img.width + "*" + img.height + ", 檔案不得超過600k");
                            }

                        }



                    }




                }
                else {



                    if (size * 1024 < img.fileSize) {
                        o1.innerText = GetMessageByID("MSG054").text;
                    }
                    else {
                        o1.innerText = "";
                        // P3109M0050 將圖片限制改為 440 * 440 by Joe
                        if (440 < img.width) {
                            o1.innerText = GetMessageByID("MSG055").text;
                            alert("目前規格:" + img.width + "*" + img.height);
                        }
                        else {
                            o1.innerText = "";
                            if (440 < img.height) {
                                o1.innerText = GetMessageByID("MSG055").text;
                                alert("目前規格:" + img.width + "*" + img.height);
                            }
                            else {
                                o1.innerText = "";


                            }
                        }
                    }




                }

            }
            else {
                o1.innerText = "";
                if (o.value.substr(len, 3) == "gif" || o.value.substr(len, 3) == "GIF") {
                    o1.innerText = "";
                    var img = new Image();
                    img.onload = function () {
                    }
                    img.src = o.value;

                    var size = getServerInfoByClient("config", "FileSize");
                    if (size * 1024 < img.fileSize) {
                        o1.innerText = GetMessageByID("MSG054").text;
                    }
                    else {
                        o1.innerText = "";
                    }

                }
                else {
                    o2.disabled = true;
                    o1.innerText = GetMessageByID("MSG040").text;
                    return false;
                }
            }

        }
        else {
            o2.disabled = true;
            o1.innerText = "";
            return false;
        }
    }
    catch (e) {

        alert(e.Message);
    }
    finally {

    }
}


//--------------------------------------------------------------------------------/
//維護程式 - 離開																  /
//功能:離開維護表單																  /
//函式名稱 = DialogBtnExit_OnClick												  /
//--------------------------------------------------------------------------------/
function DialogBtnExit_OnClick() {
    this.close();
}




function chknum(v, o) {
    var num = v.value;
    if (num > 0) {
        if (num.indexOf(".", 0) != -1) {

            if (Number(num.length) - (Number(num.indexOf(".", 0)) + 1) > 4)  //P3108M0777 碧玲 小數點改為四位

            {
                o.innerText = GetMessageByID("MSG044").text;
            }
            else {
                o.innerText = "";
                if (Number(num.length) == (Number(num.indexOf(".", 0)) + 1)) {
                    o.innerText = GetMessageByID("MSG042").text;
                }
                else {
                    o.innerText = "";
                }
            }
        }
        else {
            o.innerText = "";
            if (v.value.length > 7) {
                o.innerText = GetMessageByID("MSG043").text;
            }

        }
    }
}


function chknum1(v, o) {
    var num = v.value;
    o = $(o);
    if (num > 0) {
        if (num.indexOf(".", 0) != -1) {
            if (Number(num.length) - (Number(num.indexOf(".", 0)) + 1) > 4) //P3108M0777 碧玲 小數點改為四位

            {
                o.text(GetMessageByID("MSG044").text);
            }
            else {
                o.text("");
                if (Number(num.length) == (Number(num.indexOf(".", 0)) + 1)) {
                    o.text(GetMessageByID("MSG042").text);
                }
                else {
                    o.text("");
                }
            }
        }
        else {
            o.innerText = "";
            if (v.value.length > 7) {
                o.text(GetMessageByID("MSG045").text);
            }

        }
    }
}


function AddCboItem(Obj, Text, Text1) {
    var opt = document.createElement("OPTION");
    opt.value = Text;
    opt.text = Text1;
    Obj.options.add(opt);
}

function ClearCob(Obj) {
    while (Obj.options.length != 0) {
        Obj.options.remove(0);
    }
}
function DELIVERY_TERM() {/*
	if (document.all.drpDELIVERY_TERM.value=="FOB_Seaport")
	{
		document.all.lblSEAPORT.style.display=""; 
		document.all.txtSEAPORT.style.display=""; 
	}
	else
	{	
		document.all.lblSEAPORT.style.display="none"; 
		document.all.txtSEAPORT.style.display="none"; 
	}
	*/
}


function CLASS_DESC() {
    var result = window.showModalDialog(program_id1, '', dialogStr1, true);

}


function DELIVERY_TERM_DESC() {
    var result = window.showModalDialog(program_id2, '', dialogStr2, true);
    if (result != undefined) {
        $("#txtDELIVERY_TERM").val(result);
    }

}

function MATERIAL_TYPE_CHANGE() {
    if ($("#rdoMATERIAL_TYPE_0").prop("checked")) {
        $("#SFLAG").css("display", "");
    }
    else {
        $("#SFLAG").css("display", "none");
        $("#txtADVISED_PRICE").val("");
        $("#lblADVISED_PRICE_ERR").text("");
        $("#txtDUTY_FREE_PRICE").val("");
        $("#lblDUTY_FREE_PRICE_ERR").text("");
        $("#txtAVERAGE_PRICE").val("");
        $("#lblAVERAGE_PRICE_ERR").text("");
    }

}

function ContralPath() {

    if ($("#drpVENDOR_KIND").val() == "G") {
        $("#txtPATH2").attr('disabled', true);
        $("#txtPATH3").attr('disabled', true);
    }
    else {
        $("#txtPATH2").attr('disabled', false);
        $("#txtPATH3").attr('disabled', false);
    }
}